﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VoiceTestPlatform
{
    public class AddProjectItemViewModel : ViewModelBase
    {
        public AddProjectItemViewModel(Sound sound)
        {
            if (sound == null)
            {
                throw new ArgumentException("sound can't be null");
            }
            this.sound = sound;
            this.Path = sound.Path;


            initCommand();
        }

        private void initCommand()
        {
            OKCommand = new DelegateCommand(OKCommandAction);
            CancelCommand = new DelegateCommand(CancelCommandAction);
        }

        private void CancelCommandAction(object obj)
        {
            this.RequestClose();
        }

        private void OKCommandAction(object obj)
        {
            int con = -2;
            if (!int.TryParse(CountText, out con))
            {
                WindowsService.ShowMessageBox("播放次数解释出错");
                return;
            }

            var pi = new ProjectItem(this.sound);
            pi.PlayTimes = con;
            pi.IsLoop = IsLoop;
            //todo 位置
            ProjectManager.ProjectItems.Add(pi);
            
            this.RequestClose();
            WindowsService.ShowMessageBox("添加成功");
        }




        public DelegateCommand OKCommand { get; set; }
        public DelegateCommand CancelCommand { get; set; }



        private Sound sound;

        private string path;
        public string Path
        {
            get { return path; }
            private set
            {
                path = value;
                RaisePropertyChanged("Path");
            }
        }


        private string countText = "1";
        public string CountText
        {
            get { return countText; }
            set { countText = value; RaisePropertyChanged("CountText"); }
        }

        private bool isCountTextEnable = true;

        public bool IsCountTextEnable
        {
            get { return isCountTextEnable; }
            set { isCountTextEnable = value; RaisePropertyChanged("IsCountTextEnable"); }
        }


        private bool isLoop;

        public bool IsLoop
        {
            get { return isLoop; }
            set
            {
                isLoop = value;
                RaisePropertyChanged("IsLoop");
                if (isLoop)
                {
                    IsCountTextEnable = false;
                }
                else
                {
                    IsCountTextEnable = true;
                }
            }
        }



    }
}
